<!--
 * @Author: daidai
 * @Date: 2022-02-20 16:16:42
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2022-10-25 09:18:22
 * @FilePath: \web-pc\src\pages\big-screen\view\indexs\left-center.vue
-->
<template>
  <div v-if="pageflag" class="chart-container">
    <Echart id="charts_rcb" :options="options" class="left_center_inner" ref="charts" height="180px" />
    <!-- 底座背景 -->
    <div class="bg"></div>
  </div>
  <Reacquire v-else @onclick="getData" style="line-height: 200px">
    重新获取
  </Reacquire>
</template>

<script>
import { currentPOST } from 'api/modules';
import { colorsA, colorsB, legend, xAxis, yAxis } from '@/config/EChartVar';
import { graphic } from 'echarts';
import { getPie3D, getParametricEquation } from '@/utils/chart'; //工具类js，页面路径自己修改

export default {
  data() {
    return {
      options: {},
      optionData: [
        {
          name: '其他',
          value: 55,

          itemStyle: {
            color: '#269CA7',
          },
        },
        {
          name: '木材',
          value: 24,
          itemStyle: {
            color: '#EF8036',
          },
        },
        {
          name: '轻工原料及制品',
          value: 12,
          itemStyle: {
            color: '#A4D9F5',
          },
        },
        {
          name: '机械、设备、电器',
          value: 5,
          itemStyle: {
            color: '#F6C558',
          },
        },
        {
          name: '钢铁',
          value: 2,
          itemStyle: {
            color: '#A4DFF5',
          },
        },
        {
          name: '煤炭及制品',
          value: 1,
          itemStyle: {
            color: '#A4FFF5',
          },
        },
        {
          name: '矿建材料',
          value: 1,
          itemStyle: {
            color: '#FFD9F5',
          },
        },
      ],
      pageflag: true,
      timer: null,
    };
  },
  created() {
    this.getData();
  },
  mounted() { },
  beforeDestroy() {
    this.clearData();
  },
  methods: {
    clearData() {
      if (this.timer) {
        clearInterval(this.timer);
        this.timer = null;
      }
    },
    getData() {
      this.pageflag = true;

      this.$nextTick(() => {
        this.init();
      });
      // this.switper();
    },
    //轮询
    switper() {
      if (this.timer) {
        return;
      }
      let looper = (a) => {
        this.getData();
      };
      this.timer = setInterval(
        looper,
        2000 // this.$store.state.setting.echartsAutoTime // staticAutoTime
      );
      let myChart = this.$refs.charts.chart;
      myChart.on('mouseover', (params) => {
        this.clearData();
      });
      myChart.on('mouseout', (params) => {
        this.timer = setInterval(
          looper,
          2000 // this.$store.state.setting.echartsAutoTime // staticAutoTime
        );
      });
    },
    init(currentData) {
      let legend = {
        orient: "horizontal",
        top: '10%',
        // width: 200,
        // height: 100,
        x: 'left',
        left: '74%',
        itemGap: 20,
        formatter: function (param) {
          return param;
        },
      };
      // 传入数据生成 option, 构建3d饼状图, 参数工具文件已经备注的很详细
      const options = getPie3D(this.optionData, 0.85, 115, 16, 10, 0.9, legend);
      // // 是否需要label指引线，如果要就添加一个透明的2d饼状图并调整角度使得labelLine和3d的饼状图对齐，并再次setOption
      // options.series.push({
      //   name: '电梯状态', //自己根据场景修改
      //   backgroundColor: 'transparent',
      //   type: 'pie',
      //   label: {
      //     opacity: 1,
      //     fontSize: 13,
      //     lineHeight: 20,
      //   },
      //   startAngle: -40, // 起始角度，支持范围[0, 360]。
      //   clockwise: false, // 饼图的扇区是否是顺时针排布。上述这两项配置主要是为了对齐3d的样式
      //   radius: ['20%', '50%'],
      //   center: ['50%', '50%'],
      //   data: this.optionData,
      //   itemStyle: {
      //     opacity: 0, //这里必须是0，不然2d的图会覆盖在表面
      //   },
      // });
      options.series.push({
        // backgroundColor: 'transparent',
        name: '发货品类占比', //自己根据场景修改
        type: 'pie',
        label: {
          // show: true,
          opacity: 1,
          fontSize: 13,
          lineHeight: 20,
          // normal: {
          show: true,
          formatter: '{d}%' // 自定义标签格式，{b} 表示名称，{d} 表示数据值
          // }
        },
        startAngle: -30, // 起始角度，支持范围[0, 360]。
        clockwise: false, // 饼图的扇区是否是顺时针排布。上述这两项配置主要是为了对齐3d的样式
        radius: ['20%', '60%'],
        // center: ['50%', '30%'],
        data: this.optionData,
        itemStyle: {
          opacity: 0, //这里必须是0，不然2d的图会覆盖在表面
        },
      });
      this.options = options;
    },
  },
};
</script>
<style lang="scss" scoped>
.chart-container {
  position: relative;
  width: 540px;
  height: 100%;

  .box {
    position: absolute;
    top: 16px;
    left: 10px;
    width: 400px;
    height: 70px;
    z-index: 0;
    // border: 1px solid red;
    display: flex;
    justify-content: space-between;

    .box-info {
      // border: 1px solid red;
      width: 100px;
      // line-height: 78px;
      text-align: center;
      color: #fff;
      font-size: 14px;
      font-weight: 500;
      // padding-left: 50px;

      background: url('../../../assets/img/launch/home/rcc_bg.png') no-repeat center;
      // background-size: cover;
      background-size: 80% 80%;

      .light {
        margin-top: -10px;
        margin-bottom: 10px;
        // padding-left: 10px;
        color: #ffb507;
        font-size: 20px;
        font-weight: 600;
        // font-family: 'YouSheBiaoTiHei';
      }
    }
  }

  .left_center_inner,
  .bg {
    // margin-left: -50px;
    margin-top: 10px;
    width: 100%;
    height: 100%;
  }

  .left_center_inner {
    position: absolute;
    top: -25px;
    left: -76px;
    // width: calc(100% + 100px);
    z-index: 1;
  }

  .bg {
    position: absolute;
    // bottom: 2px;
    top: 11px;
    left: 25%;
    // z-index: -1;
    width: 290px;
    height: 165px;
    background: no-repeat center;
    background-image: url('../../../assets/img/launch/pie_bg1.png');
    background-size: 90% 90%;
    transform: translateX(-30%);
  }
}
</style>
